//package com.calmcar.adas.ldw;
//
//import android.content.Context;
//import android.util.Log;
//
//import com.calmcar.adas.apiserver.model.AdasPoint;
//import com.calmcar.adas.apiserver.model.LdwDetectInfo;
//import com.calmcar.adas.apiserver.out.CvCameraViewFrame;
//import com.calmcar.adas.apiserver.AdasConf;
//import com.calmcar.adas.dao.CalmCarLdwData;
//import com.calmcar.adas.service.FileProcessServer;
//import com.calmcar.adas.service.FrameSplitProcess;
//import com.calmcar.adas.service.MatProcess;
//import com.google.gson.Gson;
//import com.lisence.util.LisenceManager;
//
//import org.opencv.core.Mat;
//import org.opencv.core.Rect;
//import org.opencv.core.Size;
//import org.opencv.imgproc.Imgproc;
//
//import java.util.List;
//
//import tianjin.calmcar.calmcar_adas.AdasWraper;
//
///**
// * Created by lelexiao on 2018/5/2.
// */
//
//public class LdwServer {
//    public AdasWraper test;
//
//    public LdwServer() {
//        test=new AdasWraper();
//    }
//
////    private LisenceManager lisenceManager;
//    public void initLDWService(Context mContext){
//        lisenceManager=new LisenceManager(mContext);
//        FileProcessServer.setLDWConf(mContext,this);
//
//        test.Init();
//        test.setLDWParameter((short) 30,0.80f);
//    }
////
////    public  String   generateKmmiStr(){
////        return test.getKimiStr();
////    }
////
////    public String   getLaneDetectDefault(){
////        return test.lane_detect_default();
////    }
////
////    public String   laneDetectProcess(byte[] image,int height,int width,int image_type){
////        return   test.lane_detect( image,  height, width, 3);
////
////    }
////
////    public void  setSetFaultVanishPoint(){
////        String res_dect = getLaneDetectDefault();
////        Gson gson = new Gson();//来源于Gson.jar
////        CalmCarLdwData laneinfoBean = gson.fromJson(res_dect, CalmCarLdwData.class);
////    }
//
//    public LdwDetectInfo laneDetectProcessNew(byte[] image, int height, int width, int image_type){
//        LdwDetectInfo ldwDetectInfo=new LdwDetectInfo();
//        String result= test.lane_detect( image,  height, width, 3);
//        System.out.println("车道线检测结果： " +result);
//        Gson gson = new Gson();//来源于Gson.jar
//        CalmCarLdwData laneinfoBean = gson.fromJson(result, CalmCarLdwData.class);
//        int sDepartureOrientation ;
//        int sLaneDetectionResult ;
//        try {
//            List<CalmCarLdwData.CalmCarPoint>   curZone = laneinfoBean.getCurrentZone();
//            sDepartureOrientation = laneinfoBean.getSDepartureOrientation();
//            sLaneDetectionResult = laneinfoBean.getSLaneDetectionResult();
//            ldwDetectInfo.setDetectState(sDepartureOrientation);
//            ldwDetectInfo.setDetectResult( sLaneDetectionResult);
//
//
//            ldwDetectInfo.setVpy0(laneinfoBean.getVpy0());
//            ldwDetectInfo.setVpy1(laneinfoBean.getVpy1());
//
//            Log.e("vp",laneinfoBean.getVpy0()+","+laneinfoBean.getVpy1() + "," +"******************");
//
//            switch(sDepartureOrientation ){
//                case -1:
//                    ldwDetectInfo.setLdwType(0);
//                    for (int j=1;j<curZone.size();j++){
//                        ldwDetectInfo.lineRect[j-1] = new AdasPoint(curZone.get(j).getX(), curZone.get(j).getY());
//                    }
//                    break;
//                case 0:
//                    ldwDetectInfo.setLdwType(-1);
//                    break;
//                case 1://正常
//                    for (int j=1;j<curZone.size();j++){
//                        ldwDetectInfo.lineRect[j-1]  =  new AdasPoint(curZone.get(j).getX(), curZone.get(j).getY());
//                    }
//                    ldwDetectInfo.setLdwType(1);
//                    if (sLaneDetectionResult==2 || sLaneDetectionResult==3 || sLaneDetectionResult==6 || sLaneDetectionResult==7){
//                        if((ldwDetectInfo.lineRect[0].getY()==ldwDetectInfo.lineRect[5].getY())&&(ldwDetectInfo.lineRect[1].getY()==ldwDetectInfo.lineRect[4].getY())&&(ldwDetectInfo.lineRect[2].getY()==ldwDetectInfo.lineRect[3].getY())){
//                            if ((ldwDetectInfo.lineRect[2].getX()< AdasConf.centerX )&&ldwDetectInfo.lineRect[3].getX() > AdasConf.centerX ){
//                                if (ldwDetectInfo.lineRect[0].getY()<ldwDetectInfo.lineRect[1].getY() && ldwDetectInfo.lineRect[1].getY()<ldwDetectInfo.lineRect[2].getY() &&ldwDetectInfo.lineRect[5].getY()<ldwDetectInfo.lineRect[4].getY()&&ldwDetectInfo.lineRect[4].getY()<ldwDetectInfo.lineRect[3].getY())
//                                    ldwDetectInfo.setLdwType(1);
//                            }
//                        }
//                    }
//                    break;
//                case 2://左偏
//                    for (int j=1;j< curZone.size();j++){
//                        ldwDetectInfo.lineRect[j-1]  = new AdasPoint(curZone.get(j).getX(), curZone.get(j).getY());
//                    }
//                    ldwDetectInfo.setLdwType(2);
//                    if (sLaneDetectionResult==2 || sLaneDetectionResult==3 || sLaneDetectionResult==6 || sLaneDetectionResult==7){
//                        if((ldwDetectInfo.lineRect[0].getY()==ldwDetectInfo.lineRect[5].getY())&&(ldwDetectInfo.lineRect[1].getY()==ldwDetectInfo.lineRect[4].getY())&&(ldwDetectInfo.lineRect[2].getY()==ldwDetectInfo.lineRect[3].getY())){
//                            if ((ldwDetectInfo.lineRect[2].getX()< AdasConf.centerX )&&ldwDetectInfo.lineRect[3].getX() > AdasConf.centerX ){
//                                if (ldwDetectInfo.lineRect[0].getY()<ldwDetectInfo.lineRect[1].getY() && ldwDetectInfo.lineRect[1].getY()<ldwDetectInfo.lineRect[2].getY() &&ldwDetectInfo.lineRect[5].getY()<ldwDetectInfo.lineRect[4].getY()&&ldwDetectInfo.lineRect[4].getY()<ldwDetectInfo.lineRect[3].getY())
//                                    ldwDetectInfo.setLdwType(2);
//                            }
//                        }
//                    }
//                    break;
//                case 3://右偏
//                    for (int j=1;j<curZone.size();j++){
//                        ldwDetectInfo.lineRect[j-1]  =  new AdasPoint(curZone.get(j).getX(), curZone.get(j).getY());
//                    }
//                    ldwDetectInfo.setLdwType(3);
//                    if (sLaneDetectionResult==2 || sLaneDetectionResult==3 || sLaneDetectionResult==6 || sLaneDetectionResult==7){
//                        if((ldwDetectInfo.lineRect[0].getY()==ldwDetectInfo.lineRect[5].getY())&&(ldwDetectInfo.lineRect[1].getY()==ldwDetectInfo.lineRect[4].getY())&&(ldwDetectInfo.lineRect[2].getY()==ldwDetectInfo.lineRect[3].getY())){
//                            if ((ldwDetectInfo.lineRect[2].getX()< AdasConf.centerX )&&ldwDetectInfo.lineRect[3].getX() > AdasConf.centerX ){
//                                if (ldwDetectInfo.lineRect[0].getY()<ldwDetectInfo.lineRect[1].getY() && ldwDetectInfo.lineRect[1].getY()<ldwDetectInfo.lineRect[2].getY() &&ldwDetectInfo.lineRect[5].getY()<ldwDetectInfo.lineRect[4].getY()&&ldwDetectInfo.lineRect[4].getY()<ldwDetectInfo.lineRect[3].getY())
//                                    ldwDetectInfo.setLdwType(3);
//                            }
//                        }
//                    }
//                    break;
//            }
//        } catch (Exception e) {
//            ldwDetectInfo.setLdwType(-1);
//        }
//
//        return ldwDetectInfo;
//    }
//
//
//
////    public LdwDetectInfo laneDetectProcessForYuv(byte[] image, int height, int width){
////        Mat imageMat= MatProcess.processData(image,height,width);
////        Mat rgbMat= MatProcess.processDataRgbaToBgr(imageMat);
////        byte[] bufferTemp= MatProcess.processRgbDataToByteData(rgbMat);
////        LdwDetectInfo result= laneDetectProcessNew(bufferTemp,rgbMat.height(),rgbMat.width(),3);
////        return result;
////    }
//
//
//
//    public LdwDetectInfo laneDetectProcessForCameraView (CvCameraViewFrame inputFrame){
//        Mat mGrey = inputFrame.gray();
//        byte[] bufferTemp= MatProcess.processRgbDataToByteData(mGrey );
//        long start = System.currentTimeMillis(); //获取开始时间
//        LdwDetectInfo result= laneDetectProcessNew(bufferTemp,mGrey.height(),mGrey.width(),1);
//        long end = System.currentTimeMillis(); //获取结束时间
//        System.out.println("车道线检测时间： " +start+"----"+ (end - start) + "ms");
//        return result;
//    }
//
//
////    //显示/绘制
////    public void stopLDWService(){
////        test.Release();
////    }
//
//    public int putHsml(String hsmlHead,String hsml){
//        return test.pass(hsmlHead,hsml);
//    }
//
//
//    /**
//     * 设置视野焦点
//     * @param mv_x
//     * @param mv_y
//     */
//    public void setVPParaNew (int mv_x,int mv_y) {
//        test.setVPPara((float) mv_x,(float) mv_y);
//    }
//
//}
